<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'village-edit', //页面标示
    'pagename' => '编辑小区', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
	'footerjs'=>array('content/fuelux/fuelux','content/combodate/moment.min','content/combodate/combodate','content/calendar'),
    'head' => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<section id="content">
  <section class="main padder">
    <div class="clearfix">
      <h4><i class="fa fa-edit"></i><?php echo trim($Document['pagename'],'_');?></h4>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <section class="panel">
          <div class="panel-body">
            <form class="form-horizontal" method="post" id="form1">
              <div class="form-group">
                <label class="col-sm-1 control-label">小区名称</label>
                <div class="col-sm-3">
                  <input type="text" name="title" id="title" placeholder="" class="form-control" value="<?php echo $rs['title'];?>" />
                  <span class="help-block"></span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">搜索名称</label>
                <div class="col-sm-3">
                  <input type="text" name="ctitle" id="ctitle" placeholder="" class="form-control" value="<?php echo $rs['ctitle']?$rs['ctitle']:$rs['title'];?>" />
                  <span class="help-block">多个名称请用半角“,”或者“|”隔开</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">所属生活圈</label>
                <div class="col-sm-3">
                  <select class="day form-control" style="width:auto;" name="zone_id" id="zone_id">
                  	<option value="0">暂无生活圈</option>
                    <?php
						foreach($businessZone as $val){
					?>
                    <option value="<?php echo $val['zid'];?>" <?php if($val['zid']==$rs['zone_id']){echo 'selected="selected"';}?>><?php echo $val['ztitle'];?></option>
					<?php }?>
                    </select>
                    <span class="help-block" style="color:#FF0000">如需调整生活圈，请联系技术部清理缓存</span>
              </div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">小区LOGO</label>
                <div class="col-sm-3">
                  <input type="text" name="pic_url" id="pic_url" placeholder="" class="form-control" value="<?php echo $rs['pic_url'];?>" />
                  <span class="help-block">请上传您的LOGO图标，标准尺寸110px*110px <?php if($rs['pic_url']){?><a href="<?php echo getImgUrl($rs['pic_url']);?>">预览>></a><?php }?></span></div>
                <div class="col-sm-3">
                  <iframe width="280" height="24" src="<?php echo U('upload/index',array('id'=>'pic_url')); ?>" scrolling="no" frameborder="0"></iframe>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">所属区域</label>
                <div class="col-sm-3">
                  <input type="text" name="area_name" id="area_name" placeholder="" class="form-control" value="<?php echo $rs['area_name'];?>" readonly="readonly" />
                  <input type="hidden" name="area_id" id="area_id" placeholder="" class="form-control" value="<?php echo $rs['area_id'];?>" />
                  <span class="help-block"></span></div>
                <div class="col-sm-3"><a href="javascript:;" data-field="2" data-type="2" class="btn btn-default search-area" rel="pop">设定</a>
                <a href="javascript:;" class="clear-area btn btn-default col-md-offset-1" rel="area">清除</a></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">所属街道</label>
                <div class="col-sm-3">
                  <input type="text" name="street_name" id="street_name" placeholder="" class="form-control" value="<?php echo $rs['street_name'];?>"  readonly="readonly" />
                  <input type="hidden" name="street_id" id="street_id" placeholder="" class="form-control" value="<?php echo $rs['street_id'];?>" />
                  <span class="help-block"></span></div>
                <div class="col-sm-3"><a href="javascript:;" data-field="1" data-type="1" class="btn btn-default search-area" rel="pop">设定</a>
                <a href="javascript:;" class="clear-area btn btn-default col-md-offset-1" rel="street">清除</a></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">所属社区</label>
                <div class="col-sm-3">
                  <input type="text" name="community_name" id="community_name" placeholder="" class="form-control" value="<?php echo $rs['community_name'];?>"  readonly="readonly" />
                  <input type="hidden" name="community_id" id="community_id" placeholder="" class="form-control" value="<?php echo $rs['community_id'];?>" />
                  <span class="help-block"></span></div>
                <div class="col-sm-3"><a href="javascript:;" data-field="0" data-type="0" class="btn btn-default search-area" rel="pop">设定</a>
                <a href="javascript:;" class="clear-area btn btn-default col-md-offset-1" rel="community">清除</a></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">所属服务中心</label>
                <div class="col-sm-3">
                  <select class="day form-control" style="width:auto;" name="service_id" id="service_id">
                  	<option value="0">暂无服务中心</option>
                    <?php
						foreach($service as $val){
					?>
                    <option value="<?php echo $val['sid'];?>"  <?php if($val['sid']==$rs['service_id']){echo 'selected="selected"';}?>><?php echo $val['stitle'];?></option>
					<?php }?>
                    </select>
              </div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">开通配送</label>
                <div class="col-sm-10">
                  <div class="row">
                    <?php
						foreach($openstatus as $key=>$val){
					?>
                    <div class="col-xs-1 radio m-l-large select_no_result_type">
                      <label class="radio-custom">
                        <input type="radio" name="is_open" value="<?php echo $key;?>" <?php if ($rs['is_open']==$key){echo 'checked';}?>/>
                        <i class="fa fa-circle-o <?php if ($rs['is_open']==$key){echo 'checked';};?>"></i><?php echo $val;?></label>
                    </div>
                    <?php
						}
					?>
                  </div>
                  <p class="help-block"></p>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">物业类型</label>
                <div class="col-sm-10">
                  <div class="row">
                    <?php
						foreach($stype as $key=>$val){
					?>
                    <div class="col-xs-1 radio m-l-large select_no_result_type">
                      <label class="radio-custom">
                        <input type="radio" name="stype" value="<?php echo $key;?>" <?php if ($rs['stype']==$key){echo 'checked';}?>/>
                        <i class="fa fa-circle-o <?php if ($rs['stype']==$key){echo 'checked';};?>"></i><?php echo $val;?></label>
                    </div>
                    <?php
						}
					?>
                  </div>
                  <p class="help-block"></p>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">经纬度</label>
                <div class="col-sm-2">
                  <input type="text" name="lng" id="lng" placeholder="经度坐标..." class="form-control" value="<?php echo $rs['lng'];?>" />
                </div>
                <div class="col-sm-2">
                  <input type="text" name="lat" id="lat" placeholder="纬度坐标..." class="form-control" value="<?php echo $rs['lat'];?>" />
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">搜索</label>
                <div class="col-sm-3">
                  <input type="text" name="set_address" id="set_address" placeholder="" class="form-control" value="" />
                  <span class="help-block">直接通过地址获取坐标</span></div>
                  <div class="col-sm-3"><a href="javascript:;" id="get_address" class="btn btn-default">搜索</a></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">地图</label>
                <div class="col-sm-5">
                <script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&key=1aa6a77c877c9d026f2f7640bb722f41"></script>
				<script>
				var geocoder,map,marker = null;
				var centerInfo={"city":"<?php echo $rs['city_name'];?>","lat":"<?php echo $rs['lat'];?>","lng":"<?php echo $rs['lng'];?>"};
                var init = function() {
					var center = new qq.maps.LatLng(centerInfo.lat,centerInfo.lng);
                    var map = new qq.maps.Map(document.getElementById("container"),{
                        center: center,
                        zoom: 16
                    });
					var marker = new qq.maps.Marker({
						position: center,
						map: map
					});
					geocoder = new qq.maps.Geocoder({
						complete : function(result){
							Msg.hide();
							marker.setMap(null);
							map.setCenter(result.detail.location);
							marker = new qq.maps.Marker({
								map:map,
								position: result.detail.location
							});
						}
					});
                    qq.maps.event.addListener(map, 'click', function(event) {
						var lng=event.latLng.getLng().toFixed(8);
						var lat=event.latLng.getLat().toFixed(8);
						$("#lng").val(lng);
						$("#lat").val(lat);
						marker.setMap(null);
						center=new qq.maps.LatLng(lat,lng);
						map.setCenter(center);
						marker = new qq.maps.Marker({
							map:map,
							position: center
						});
						Msg.loading('正在解析地址...');
						$.getJSON('<?php echo U('map/address');?>',{"x":lng,"y":lat},function(res){
							Msg.hide();
							if (res.status){
								$("#address").val(res.data.path);
							}
						});
                    });
                }
				$("#get_address").click(function(){
					var address = $("#set_address").val();
					if (!address){
						Msg.error('请输入地址');
						return false;	
					}
					Msg.loading('正在解析数据...');
					geocoder.getLocation(centerInfo.city+","+address);
				})
                </script>
                <style>#container img{max-width:none}</style>
                  <div style="width:600px;height:400px" id="container"></div>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">地址</label>
                <div class="col-sm-6">
                  <textarea class="form-control" id="address" name="address"  style="height:80px"><?php echo $rs['address'];?></textarea>
                  <span class="help-block"></span></div>
              </div>
              <div class="form-group">
                <div class="col-sm-9 col-lg-offset-1">
                  <div class="col-sm-1">
                  <input name="vid" type="hidden" value="<?php echo $rs['vid'];?>" />
                    <button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
                  </div>
                  <div class="col-md-offset-2">
                    <button type="button" class="btn btn-white">取消</button>
                  </div>
                </div>
              </div>
            </form>
          </div>
        </section>
      </div>
    </div>
  </section>
</section>
<!--主体 结束--> 
<script>
var area_id=0;
var street_id=0;
var community_id=0;
var page_num=self.location.hash;
if(page_num=="") {
  page_num=1;
}else{
  page_num = page_num.substr(1);
}
function setArea(aid,aname,field){
		console.log(aid);
		console.log(aname);
		console.log(field);
		switch(field){
			case '0':
			$("#community_id").val(aid);
			$("#community_name").val(aname);
			community_id=aid;
			break;
			case '1':
			$("#street_id").val(aid);
			$("#street_name").val(aname);
			street_id=aid;
			break;
			case '2':
			$("#area_id").val(aid);
			$("#area_name").val(aname);
			area_id=aid;
			break;
		}
		$(document).trigger('close.facebox');
}
$(function(){
	$('#form1').submit(function(){
		var title=$.trim($("#title").val());
		var isOk=true;
		if (!title){
			Msg.error('小区名称不能为空');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		Msg.loading();
		  $.post('<?php echo U('village/save');?>',$(this).serialize(),function(result){
			  Msg.hide();
			  resetSubmit("#sub-ok",'保存');
			  if (result.status==1){
				Msg.ok('编辑成功',function(){
					//document.location='<?php echo U('village/index');?>'+'?p='+page_num;
					history.go(-1);
				},1000);  
			}else{
				Msg.error(result.info);
			}
		  },'json');
		  return false;
	});
	$(".search-area").click(function(){
		var field=$(this).attr('data-field');
		var type=$(this).attr('data-type');
		var fid=0;
		if (area_id&&type==1){
			fid=area_id;
		}
		if (street_id&&type==0){
			fid=street_id;
		}
		$(this).attr('href','<?php echo U('area/search',array(),true);?>&field='+field+'&type='+type+'&fid='+fid);	
	})
	$(".clear-area").click(function(){
		var t=$(this).attr("rel");
		$("#"+t+'_id').val('');
		$("#"+t+'_name').val('');
		if (t=='area'){
			area_id=0;
		}
		if (t=='street'){
			street_id=0;
		}
		return false;
	})
	init();
})
</script>
<?php
include getTpl('footer', 'public');
?>